# -*- coding: utf-8 -*-
require 'gtk2'
require './Modele/Client'
require './Modele/Parking'
require './Controler/LoadParking.rb'

class NewClient < Gtk::Builder

  def initialize(xml,parking,titre,immat)
    super()
    self << xml
    self['window1'].signal_connect("destroy") { onDestroy }
    self['window1'].show_all
    @parking=parking
    @titre=titre
    @immat=immat
    self.connect_signals{ |handler| method(handler) }
  end
  
  def on_validate
       
    if (self['nom'].text=="" || self['prenom'].text=="") then
      dialog = Gtk::Dialog.new("Information", self, Gtk::Dialog::DESTROY_WITH_PARENT,[ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_NONE ])
      dialog.signal_connect('response') { dialog.destroy }
      dialog.vbox.add(Gtk::Label.new(" Le nom et le prenom ne peuvent pas être vide ! ")) 
      dialog.show_all
    else
      client=Client.new(self['nom'].text,self['prenom'].text,@parking)
      puts "Client créé"
      str=client.se_garer(Vehicule.new(@immat),@parking.acces[1].borne)
      LoadParking.new("View/parking.glade",@titre)
      self['window1'].destroy
    end
    
  end
  
  def on_cancel
    self['window1'].destroy
  end
  
  
  def onDestroy
    self['window1'].destroy
  end

end